<?php
namespace backend\models;

use yii\base\Model;
use yii\base\InvalidParamException;
use common\models\Adminuser;
use yii\helpers\VarDumper;

/**
 * Password reset form
 */
class ResetpwdForm extends Model
{
    public $password;
    public $password_repeat;
    /**
     * @var \common\models\User
     */





    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            ['password', 'required'],
            ['password', 'string', 'min' => 6],
			['password_repeat','compare','compareAttribute'=>'password','message'=>'两次输入的密码不一致！'],
        ];
    }
    public function attributeLabels()
    {
    	return [
    			'password' => '密码',
    			'password_repeat'=>'重输密码',
    	];
    }
    /**
     * Resets password.
     *
     * @return bool if password was reset.
     */
    public function resetPassword($id)
    {
        if (!$this->validate()) {
            return null;
        }
        
        $admuser = Adminuser::findOne($id);
        $admuser->setPassword($this->password);
        $admuser->removePasswordResetToken();
        
        return $admuser->save() ? true : false;
    }
}
